package com.yuven.appframework.core.thread

import android.os.Handler
import android.os.HandlerThread
import com.yuven.baselib.utils.Logger

class BaseHandleThread @JvmOverloads constructor(val mThreadName:String = "",priority:Int = 0):HandlerThread(mThreadName,priority){
    val TAG:String  = "BaseHandleThread"
    private var mHandler:Handler ?= null

    protected override fun onLooperPrepared(){
        mHandler = getHandler()
    }

    @Synchronized
    fun post(runnable: Runnable?){
        if(runnable == null){
            Logger.i(TAG, "$mThreadName：runnable post is null")
            return
        }
        mHandler?.post(runnable)
    }

    @Synchronized
    fun postDelay(runnable: Runnable?,delayTime:Long){
        if (runnable == null) {
            Logger.i(TAG, "$mThreadName：runnable post delay is null")
            return
        }
        mHandler?.postDelayed(runnable,delayTime)
    }

    @Synchronized
    fun getHandler(): Handler? {
        if (mHandler == null) {
            mHandler = Handler(looper)
        }
        return mHandler
    }

}